package com.fourth.controller.api;

import com.fourth.service.UbGoodsService;
import com.ljx.entity.Goods;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Mr.ma
 * @since 2023/3/2 17:09
 **/
@RestController
@RequestMapping("/detail/goods")
@Api("商品操作接口")
public class UbApiGoodsController {

    @Resource
    private UbGoodsService ubGoodsService;

    @RequestMapping("findGoodsByGoodsid/{id}")
    @ApiOperation("根据goodsid查询所有商品信息")
    @ApiImplicitParam(name = "id", value = "商品编号", dataType = "Integer")
    public Result<Goods> findGoodsByGoodsid(@PathVariable Integer id){
        Goods goods = ubGoodsService.findById(id);
        if (goods != null){
            return new Result(2000,"查询成功",goods);
        }
        return new Result(5000,"查询失败",null);
    }

    @RequestMapping("getGoodsSellNum/{id}")
    @ApiOperation("根据gooodsid获取商品成交量")
    @ApiImplicitParam(name = "id", value = "商品编号", dataType = "Integer")
    public Result<String> getGoodsSellNum(@PathVariable Integer id){
        String total = ubGoodsService.getGoodsSellNum(id);
        return new Result(2000,"查询成功",total);
    }

    @RequestMapping("getStock/{id}")
    @ApiOperation("根据goodsid获取商品余量")
    @ApiImplicitParam(name = "id", value = "商品编号", dataType = "Integer")
    public Result<Integer> getStock(@PathVariable Integer id){
        String stockNum = ubGoodsService.getStock(id);
        return new Result(2000,"查询成功",Integer.parseInt(stockNum));
    }

}
